package com.xcmg.restaurant.customerservice.controller;

import com.xcmg.restaurant.apimodel.Customer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * RestaurantCustomerInstancesController
 *
 * @author diyiliu
 * @create 2024-07-17 17:43
 **/

@RestController
public class RestaurantCustomerInstancesController {

    @Autowired
    private DiscoveryClient eurekaConsumer;

    @GetMapping("/customer_service_instances")
    public Object customerServiceInstances() {

        return eurekaConsumer.getInstances("customer-feign");
    }

    static Map<Long, Customer> mockCustomerData = new HashMap();
    static{
        mockCustomerData.put(1L, new Customer(1, "Jane", "DC"));
        mockCustomerData.put(2L, new Customer(2, "John", "SFO"));
        mockCustomerData.put(3L, new Customer(3, "Kate", "NY"));
    }

    @GetMapping("/customer/{id}")
    public Customer getCustomerInfo(@PathVariable("id") Long id) {
        return mockCustomerData.get(id);
    }
}
